<style>
body {
  min-width:357px;
  overflow-x:hidden;
}

img {
  margin:5px;
  border:2px solid black;
  vertical-align:middle;
  width:75px;
  height:75px;
}
</style>

<script>

var div = document.createElement("div");
div.innerHTML = window.location;
document.body.appendChild(div);
getPhotos(id);

var regex = new RegExp("/photos/[^/]+/");
var match = regex.exec(window.location);
var nameOrId = null;
if (match) {
	regex = new RegExp("[^/]+");
	regex.lastIndex = 7; // TODO: remove magic number
	nameOrId = regex.exec(match);
}
if (nameOrId) {
	if (nameOfId.indexOf("@") != -1)
		getPhotos(nameOrId); // id in this case
	else
		getId(nameOrId); // name in this case
}

var req = null;

function getId(name) {
	req = new XMLHttpRequest();
	req.open(
		"GET",
		"http://api.flickr.com/services/rest/?" +
			"method=flickr.people.findByUsername&" +
			"api_key=505e56e36e7e092435c28c45c26a91d9&" +
			"username=" + name,
		true);
	req.onload = gotId;
	req.send(null);
}

function gotId() {
	var user = req.responseXML.getElementsByTagName("user");
	var id = user[0].getAttribute("nsid");
	var div = document.createElement("div");
	div.innerHTML = id;
	document.body.appendChild(div);
	getPhotos(id);
}

function getPhotos(id) {
	req = new XMLHttpRequest();
	req.open(
		"GET",
		"http://api.flickr.com/services/rest/?" +
			"method=flickr.people.getPublicPhotos&" +
			"api_key=505e56e36e7e092435c28c45c26a91d9&" +
			"user_id=" + id + "&" + 
			"per_page=20",
		true);
	req.onload = showPhotos;
	req.send(null);
}

function showPhotos() {
  var photos = req.responseXML.getElementsByTagName("photo");

  for (var i = 0, photo; photo = photos[i]; i++) {
    var img = document.createElement("image");
    img.src = constructImageURL(photo);
    document.body.appendChild(img);
  }
}

// See: http://www.flickr.com/services/api/misc.urls.html
function constructImageURL(photo) {
  return "http://farm" + photo.getAttribute("farm") +
      ".static.flickr.com/" + photo.getAttribute("server") +
      "/" + photo.getAttribute("id") +
      "_" + photo.getAttribute("secret") +
      "_s.jpg";
}
</script>